#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: fu
"""

import Common
import Config

class Box:
    def __init__(self, left = -20, top = -10):
        self.rect = Common.pygame.Rect(left, top, 40, 40)
        self.dir = Common.pygame.K_RIGHT
        
    def remove(self):
        self.rect.x = -20
        self.rect.y = -10
    
    def set(self, m = Config.MARGIN):
        if self.rect.x == -20 and self.rect.y == -10:
            self.rect.top  = Common.random_even(m * 2, Config.MAP_Y - m * 2) * 10
            self.rect.left = Common.random_even(m, Config.MAP_X - m) * 20
            
            self.color = 'img/Blocks/' + 'Box 1' + '.png'
            
    def move(self, d):
        if d == Common.pygame.K_LEFT:
            self.rect.left -= 20
            self.rect.top -= 10
        elif d == Common.pygame.K_RIGHT:
            self.rect.left += 20
            self.rect.top += 10
        elif d == Common.pygame.K_UP:
            self.rect.left += 20
            self.rect.top -= 10
        elif d == Common.pygame.K_DOWN:
            self.rect.left -= 20
            self.rect.top += 10
            
    def __eq__(self, other):
        return self.rect == other.rect
    